#include<iostream>
#include<string>
using namespace std;

class String
{
public:
	String(const char* str = nullptr)
	{
		if (str != nullptr)
		{
			m_data = new char[strlen(str) + 1];
			strcpy(m_data, str);
		}
		else
		{
			m_data = new char[1];
			m_data[0] = '\0';
		}
	}
	String(const String& other)
	{
		m_data = new char[strlen(other.m_data) + 1];
		strcpy(m_data, other.m_data);
	}
	~String()
	{
		delete[]m_data;
		m_data = nullptr;
	}
	//Stringֵ&是为了可以连续赋值 str1=str2=str3;
	String& operator=(const String& other)
	{
		if (this == &other)
		{
			return *this;
		}
		delete[]m_data;
		m_data = new char[strlen(other.m_data) + 1];
		strcpy(m_data, other.m_data);
		return *this;
	}

private:
	char* m_data;
};
#if 0
int main()
{
	//调用String(const char* str = nullptr)构造函数
	String str1;
	String str2("hello");
	String str3 = "hello";

	//调用String(const String& other)拷贝构造函数
	String str4(str3);
	String str5 = str3;

	//调用String& operator=(const String& other)操作符重载
	str1 = str2;
	return 0;
}
#endif